package com.jfinal.weixin.demo.chengyu;

import com.alibaba.fastjson.JSON;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

/**
 * Created by wangxiaoyang on 16/8/28.
 */
public class ChengyuApi {

    private static final String radomUrl = "http://api.avatardata.cn/ChengYu/Random?key=df67478366464c63a056ec08f1a3e32a";
    private static final String baseUrl = "";

    public static void main(String[] args) {
        getChenyuBean(new OkHttpClient());
    }

    public static ChengyuBean getChenyuBean(OkHttpClient httpClient) {

        Request request = new Request.Builder()
                .url(radomUrl)
                .build();
        try {
            Response response = httpClient.newCall(request).execute();
            String resule = response.body().string();
            System.out.println(resule);
            ChengyuBean chengyuBean = JSON.parseObject(resule,ChengyuBean.class);
            System.out.println(chengyuBean.format());
            return chengyuBean;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;

    }

}
